package allrobots.test;

import jakarta.websocket.OnClose;
import jakarta.websocket.OnMessage;
import jakarta.websocket.OnOpen;
import jakarta.websocket.Session;
import jakarta.websocket.server.PathParam;
import jakarta.websocket.server.ServerEndpoint;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.logging.Logger;

@ServerEndpoint(value = "/api/websocket/{user_id}")
@Component
public class WebSocketServer {
//    private static Logger L= (Logger) LoggerFactory.getLogger(WebSocketServer.class);

    private String userId;
    @OnOpen
    public void onOpen(Session session, @PathParam("user_id")String userId){
        this.userId=userId;
        System.out.println("连接建立");
    }
    @OnClose
    public void onClose(){
        System.out.println("连接关闭");
    }
    @OnMessage
    public void onMessage(String message,Session session){
        try {
            System.out.println(message);
            session.getBasicRemote().sendText("11111111");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
